package com.gimi.cloud.jimi.common.utils;
import  java.util.Random;

/**
 * 流水号生成工具
 */
public class SerialNoUtil {
    /**
     * 生成流水号
     * @param round 随机数的范围（越大随机率越高）
     * @param length 流水号长度
     * @param range 范围（支持：1）
     * @return
     */
    public static String createSerialNo(int round, int length, int range) {
        String key = "";
        for (int i = 0; i < length; i++) {
            Random rand = new Random();
            int random = rand.nextInt(round) % range;

            switch (random) {
                case 0:
                    key += "0";
                    break;
                case 1:
                    key += "1";
                    break;
                case 2:
                    key += "2";
                    break;
                case 3:
                    key += "3";
                    break;
                case 4:
                    key += "4";
                    break;
                case 5:
                    key += "5";
                    break;
                case 6:
                    key += "6";
                    break;
                case 7:
                    key += "7";
                    break;
                case 8:
                    key += "8";
                    break;
                case 9:
                    key += "9";
                    break;
                case 10:
                    key += "A";
                    break;
                case 11:
                    key += "B";
                    break;
                case 12:
                    key += "C";
                    break;
                case 13:
                    key += "D";
                    break;
                case 14:
                    key += "E";
                    break;
                case 15:
                    key += "F";
                    break;
                default:
                    i--;
            }
        }
        return key;
    }
}
